package com.lanou.activity.Service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lanou.activity.Service.PlainInfoService;
import com.lanou.activity.mapper.PlainInfoMapper;
import com.lanou.activity.utils.Constant;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class PlainInfoServiceImpl implements PlainInfoService{

@Resource
private PlainInfoMapper plainInfoMapper;

    @Override
    public List<Map<String, Object>> selectsale() {
        return plainInfoMapper.selectsale();
    }

    @Override
    public List<Map<String, Object>> selectdis() {
        return plainInfoMapper.selectdis();
    }

    @Override
    public PageInfo<Map<String, Object>> selectPlain(Map<String, Object> params) {
        Integer currentPage = params.get("currentPage") == null ? 1:Integer.parseInt((String)params.get("currentPage"));
        Integer pageSize = params.get("pageSize") == null ? Constant.CURRENTPAGE : Integer.parseInt((String) params.get("pageSize"));

        PageHelper.startPage(currentPage, pageSize);
        List<Map<String,Object>> list = plainInfoMapper.selectPlain(params);
        //用PageInfo对结果进行包装
        PageInfo<Map<String,Object>> page = new PageInfo<Map<String,Object>>(list);
        //测试PageInfo全部属性
        return page;
    }

    @Override
    public void updatePlain(Map<String, Object> param) {
        plainInfoMapper.updatePlain(param);
    }

    @Override
    public List<Map<String, Object>> selectPlainById(Map<String, Object> param) {
        return plainInfoMapper.selectPlain(param);
    }


    @Override
    public List<Map<String, Object>> selectlimit() {
        return plainInfoMapper.selectlimit();
    }

    @Override
    public int addPlain(Map<String, Object> params) {
        return  plainInfoMapper.addPlain(params);
    }
}
